<?php
/**
 * Created by b17
 * 2/28/12 6:56 PM
 */

class App_Plugin_CookieAuth extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch()
    {
        if (!\Zend_Auth::getInstance()->hasIdentity()) {
            if (array_key_exists('user', $_COOKIE)) {
                $cookieData = $_COOKIE['user'];
                $usersManager = new \Managers\Users();
                $result = $usersManager->cookieAuth($cookieData);
                if (!$result) {
                    setcookie('user', '', time(), '/');
                }
            }

        }
    }
}
